var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var settings = require('./settings');
var routes = require('./routes/index');

var app = express();

app.set('port', process.env.PORT || 1234);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
//创建connection
var connection = mysql.createConnection(settings);
//开始连接
connection.connect(function(err){
	if(err){
		console.log(err)
	}else{
		console.log('[connection connect] succeed');
	}
});
var selectSQL = 'select * from think_user limit 2';
connection.query(selectSQL, function(err,rows) {
  
	    console.log(rows[0]);
	
  
});
//结束连接
connection.end(function(err){
	if(err){       
		return;
	}
	console.log('[connection end] succeed!');
});
routes(app);

app.listen(app.get('port'), function() {
  console.log('Express server listening on port ' + app.get('port'));
});
